home *** CD-ROM | disk | FTP | other *** search
/ MaxiMac 2000 December / MaxiMac 109.iso / Macworld on CD n°109 / Applications (Mac OS X PB) / MacOSX ScreenSavers / Source Code / Icon / IconImage.m < prev    next >
Encoding:
Text File  |  2000-08-01  |  1.6 KB  |  72 lines  |  [????/????]

  1. /* IconImage.m created by epeyton on Fri 17-Sep-1999 */
  2.  
  3. #import "IconImage.h"
  4. #import <ScreenSaver/ScreenSaver.h>
  5.  
  6. @implementation IconImage
  7.  
  8. - (id)initWithPath:(NSString *)imagePath inRect:(NSRect)rect parent:(id)passedParent
  9. {
  10.     self = [super init];
  11.  
  12.     parent = passedParent;
  13.     
  14.     // load the app icon from this place
  15.     image = [[[NSWorkspace sharedWorkspace] iconForFile:imagePath] retain];
  16.  
  17.     fade = SSRandomFloatBetween (0.1, 0.5);
  18.     blackFade = .2;
  19.     [image setScalesWhenResized:YES];
  20.  
  21.     [image setSize:rect.size];
  22.     
  23.     blackImage = [[NSImage alloc] initWithSize:rect.size];
  24.     [blackImage setBackgroundColor:[NSColor blackColor]];
  25.     [blackImage lockFocus];
  26.     PSsetgray(0.0);
  27.     NSRectFill(NSMakeRect(0.0,0.0,[blackImage size].width,[blackImage size].height));
  28.     [blackImage unlockFocus];
  29.     
  30.     // place it at point
  31.     imagePoint = rect.origin;
  32.  
  33.     counter = 0;
  34.     life = SSRandomFloatBetween(10.0, 20.0);
  35.     
  36.     return self;
  37. }
  38.  
  39. - (void)display
  40. {    
  41.     if (fade < 1) {
  42.         fade += .01;
  43.     } else {
  44.         counter++;
  45.     }
  46.  
  47.     if (counter > life) {
  48.         blackFade += .01;
  49.         [blackImage dissolveToPoint:imagePoint fraction:blackFade];
  50.         if (blackFade > 1) {
  51.             [parent removeIconImage:self];
  52.         }
  53.     } else if (fade < 1) {
  54.         [image dissolveToPoint:imagePoint fraction:fade];
  55.     }
  56. }
  57.  
  58. - (void)dealloc
  59. {
  60.     [image release];
  61.     [blackImage release];
  62.     [super dealloc];
  63.     return;
  64. }
  65.  
  66. - (NSRect)imageRect
  67. {
  68.     return(NSMakeRect(imagePoint.x,imagePoint.y,[blackImage size].width,[blackImage size].height));
  69. }
  70.  
  71. @end
  72.